<!--#include file="common/header.html"-->
<body>
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding">
                    <form class="layui-form" action="/education/admin/chargeType">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="关键字">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">
                        <button class="layui-btn layui-btn-small modal-catch" beforeFun="beforeAdd"
                                data-params='{"content":".add-subcat", "title":"添加","type":"1", "full":"true", "maxmin":"true"}'>
                            <i class="iconfont">&#xe649;</i> 添加
                        </button>
                        <!--<button class="layui-btn layui-btn-small" onclick="viewDetail();">
                            <i class="iconfont">&#xe653;</i>编辑
                        </button>-->
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox" data-params='{"url": "/education/admin/chargeType/delete"}'>
                            <i class="iconfont">&#xe626;</i> 删除
                        </button>
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>
    <div class="add-subcat">
        <form class="layui-form layui-form-pane" action="/education/admin/chargeType/save" id="form1">
            <input type="hidden" name="id">

            <div class="layui-form-item">
                <label class="layui-form-label">金额</label>
                <div class="layui-input-inline">
                    <input type="number" name="money" required jq-verify="required" jq-error="必须为数字" value="0"
                           class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 150px;">赠送的优惠券</label>
                <div class="layui-input-inline">
                    <select name="gift_coupon_id" id="gift_coupon_id">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="number" name="ord" required jq-verify="required" jq-error="必须为数字" value="0"
                           class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" jq-submit jq-filter="submit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</body>
<script id="list-tpl" type="text/html"
        data-params='{"url":"/education/admin/chargeType","dataName":"chargeTypeData","pageid":"#page", "method":"post"}'>
    <table id="example" class="layui-table lay-even" data-name="chargeTypeData" data-tplid="list-tpl">
        <thead>
        <tr>
            <th width="30"><input type="checkbox" id="checkall" data-name="checkbox" lay-filter="check"
                                  lay-skin="primary"></th>
            <th width="80">面值(元)</th>
            <th width="80">赠送优惠券</th>
            <th>优惠券使用条件</th>
            <th width="120">开始时间</th>
            <th width="120">结束时间</th>
            <th width="170">发布时间</th>
            <th width="140">操作</th>
        </tr>
        </thead>
        <tbody>
        {{# layui.each(d.list, function(index, item){ }}
        <tr>
            <td><input type="checkbox" name="checkbox" value="{{ item.id}}" lay-skin="primary"></td>
            <td>{{ item.money }} </td>
            <td>{{ item.face_value }} </td>
            <td>{{ item.use_desc }} </td>
            <td>{{ item.start_date ||''}} </td>
            <td>{{ item.end_date ||'' }} </td>
            <td>{{# if(item.create_time == null){ }} {{#  } else { }} {{ item.create_time}}  {{#  } }}</td>
            <td>
                <button class="layui-btn layui-btn-mini" onclick="viewDetail('{{item.id}}');">
                    <i class="iconfont">&#xe653;</i>编辑
                </button>
                <button class="layui-btn layui-btn-mini layui-btn-danger ajax"
                        data-list='{"key":"id={{ item.id}}","msg":true,"render":"true","action":"del"}'
                        data-params='{"url": "/education/admin/chargeType/delete","data":"ids={{ item.id}}", "method":"post", "confirm":"true"}'>
                    <i class="iconfont">&#xe626;</i>删除
                </button></td>
            </td>
        </tr>
        {{# }); }}
        </tbody>

    </table>
</script>
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<!--#include file="common/version.html"-->
<script>
    layui.use('user_list');

    /*
    初始化部分
     */
        layui.use('jquery', function () {
            var $ = layui.jquery;
            $(function () {
                var arr = ['<option value="">请选择</option>'];
                $.ajax({
                    dataType:'json',
                    method:'post',
                    url: '/education/api/coupon',
                    data: {'pageSize':100},
                    async: false,
                    success: function (rs) {
                        if (rs.code == 200) {
                            $.each(rs.data, function (i, n) {
                                var v ='<option value={v}>{n}</option>'
                                    .replace('{v}', n.id).replace('{n}', n.name)
                                arr.push(v);
                            })
                        }
                        $('#gift_coupon_id').html(arr.join(''));
                    }
                });
            })
        });

    function beforeAdd(obj){
        $('#form1').attr('action', '/education/admin/chargeType/save');
    }

    function viewDetail(ids){
        var index = layer.open({
            type: 1,
            title:'编辑',
            content: $('.add-subcat')
        });
        layer.full(index);
        $('#form1').attr('action', '/education/admin/chargeType/update/' + ids);
        restGet('/education/admin/chargeType/view/' + ids, null, $('#form1'), function(rs){
            console.log(rs)
        })
    }
</script>

</html>